package com.jxj.GUI;

import com.jxj.mapper.mapperUser;
import com.jxj.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

class chuliGUI extends JFrame {
    private SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
    mapperUser mapperuser = sqlSession.getMapper(mapperUser.class);
    newmain n1 = new newmain();

    public void chuliWindow(JTable table) {
        JFrame frame = new JFrame("学生反馈处理");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        int DIALOG_WHITE = 600;//宽度
        int DIALOG_HEIGHT = 600;//高度
        Point point = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
        frame.setBounds(point.x - DIALOG_WHITE / 2, point.y - DIALOG_HEIGHT / 2, DIALOG_WHITE, DIALOG_HEIGHT);
        frame.setVisible(true);
        frame.setIconImage(new ImageIcon("C:\\Users\\Lenovo\\Desktop\\icon.png").getImage());
        frame.setLayout(null);
        JLabel ting = new JLabel("反馈内容");
        ting.setBounds(30, 5, 100, 30);
        frame.add(ting);
        JTextArea things = new JTextArea();
        things.setEditable(false);
        things.setBounds(30, 50, 500, 200);
        int row = table.getSelectedRow();
        Object thingobj = table.getValueAt(row, 3);
        things.setText((String) thingobj);
        frame.add(things);
        JLabel l1 = new JLabel("回复");
        l1.setBounds(30, 250, 100, 30);
        frame.add(l1);
        JTextArea thinghui = new JTextArea();
        thinghui.setBounds(30, 280, 500, 200);
        frame.add(thinghui);
        JButton yes = new JButton("通过");
        yes.setLocation(30, 500);
        yes.setSize(100, 30);
        n1.changeButton(yes);
        JButton no = new JButton("驳回");
        n1.changeButton(no);
        no.setLocation(430, 500);
        no.setSize(100, 30);
        frame.add(yes);
        frame.add(no);
        yes.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int hang = (int) table.getValueAt(row, 0);
                mapperuser.chuli(hang);
                JOptionPane.showMessageDialog(
                        frame, // 父组件，如果为 null，则弹窗会显示在屏幕中央
                        "处理成功",
                        "提示",
                        JOptionPane.INFORMATION_MESSAGE // 提示类型，这里使用信息类型
                );
                frame.setVisible(false);
            }
        });
        no.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int hang = (int) table.getValueAt(row, 0);
                mapperuser.chuli(hang);
                JOptionPane.showMessageDialog(
                        frame, // 父组件，如果为 null，则弹窗会显示在屏幕中央
                        "处理成功",
                        "提示",
                        JOptionPane.INFORMATION_MESSAGE // 提示类型，这里使用信息类型
                );
                frame.setVisible(false);
            }
        });

    }

}
